-
Notifications
You must be signed in to change notification settings - Fork 220
Extend existence check in URLImageDescriptor when running without OSGi #3106
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
This e.g. breaks the scaled image data retrieval in DPIUtil:
|
Test Results 2 778 files ±0 2 778 suites ±0 1h 38m 25s ⏱️ - 1m 17s For more details on these failures, see this check. Results for commit d8c699b. ± Comparison against base commit 789b373. ♻️ This comment has been updated with latest results. |
5c2261f
to
33196c4
Compare
if (FILE_PROTOCOL.equalsIgnoreCase(url.getProtocol())) | ||
return IPath.fromOSString(url.getFile()).toOSString(); | ||
if (FILE_PROTOCOL.equalsIgnoreCase(url.getProtocol())) { | ||
String filePath = IPath.fromOSString(url.getFile()).toOSString(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can't we use Path.of(...)
directly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think Path.of(url.toURI()).toString()
is even less readable than IPath.fromOSString(url.getFile()).toOSString()
, in addition to also having to deal with the URISyntaxException.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IPath.fromOSString(url.getFile()).toOSString()
to be honest this looks really bogus, why not simply
String filePath = IPath.fromOSString(url.getFile()).toOSString(); | |
String filePath = url.getFile(); |
but I more was about that below you are using a path anyways so
p = Path.of(url.toURI())
if (Files.exists(Path.of(p))) {
return p.toString();
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why not simply
As mentioned, you now have to also worry about the potential URISyntaxException and are now depending on something ambiguous as a toString()
method...
But as long as the method behaves consistently, I don't really mind either way.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What now raises the question if we should not extract it to an own method, and why we need an existence checks for files but not for regular URLs ... so maybe the caller will check for the existence anyways later on?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What now raises the question if we should not extract it to an own method, and why we need an existence checks for files but not for regular URLs
Because URLs are not used in combination with the ImageFileNameProvider
. The reason while files get a special treatment is primarily performance and I don't think extracting this logic to a separate method only adds unnecessary complexity.
so maybe the caller will check for the existence anyways later on?
The caller will not. Otherwise this issue wouldn't even exist in the first place. And this is also not expected, as specified in the JavaDoc;
eclipse.platform.ui/bundles/org.eclipse.jface/src/org/eclipse/jface/resource/URLImageDescriptor.java
Line 247 in 789b373
* @return {@link String} or <code>null</code> if the file cannot be found |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think extracting this logic to a separate method only adds unnecessary complexity.
At least you would not need to adjust the logic in two places now ...
as specified in the JavaDoc;
If I read it correctly FileNameProvider
it should only return null
if the zoom != 100 .. but this seems flawed before.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
At least you would not need to adjust the logic in two places now ...
Updated.
If I read it correctly FileNameProvider it should only return null if the zoom != 100 .. but this seems flawed before.
That is true and probably also why the IOException is explicitly logged in such a case. But that's something that goes beyond the scope of this PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@laeubi I've moved the conversion from URL to String to a separate method. Do you see anything else I've missed? Otherwise I'd merge this within the next days.
abd678c
to
693d086
Compare
This extends the check added in cff785d to also consider the case when OSGi isn't running. Otherwise a path to a non-existent file is returned, thus breaking the contract specified in the JavaDoc.
693d086
to
d8c699b
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks good to me.
Test failure on MacOS is unrelated: #294 |
This change leads to a bunch of exceptions when starting a product for me. Seems to be related to image paths containing whitespaces.
@ptziegler can you please have a look? |
I stopped following the long discussion here but |
Hence why I was reluctant to use it in the first place... I'm on it. The error is thrown when e.g. converting a file to URL via |
See #3115 |
This extends the check added in cff785d to also consider the case when OSGi isn't running. Otherwise a path to a non-existent file is returned, thus breaking the contract specified in the JavaDoc.